home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Resources / Developer & Web Development Tools / Inno Setup 5.2.3 / isetup-5.2.3.exe / {app} / Examples / CodeDll.iss < prev    next >
Text File  |  2007-12-06  |  3KB  |  73 lines

  1. ; -- CodeDll.iss --
  2. ;
  3. ; This script shows how to call DLL functions at runtime from a [Code] section.
  4.  
  5. [Setup]
  6. AppName=My Program
  7. AppVerName=My Program version 1.5
  8. DefaultDirName={pf}\My Program
  9. DisableProgramGroupPage=yes
  10. UninstallDisplayIcon={app}\MyProg.exe
  11. OutputDir=userdocs:Inno Setup Examples Output
  12.  
  13. [Files]
  14. Source: "MyProg.exe"; DestDir: "{app}"
  15. Source: "MyProg.chm"; DestDir: "{app}"
  16. Source: "Readme.txt"; DestDir: "{app}"; Flags: isreadme
  17. ; Install our DLL to {app} so we can access it at uninstall time
  18. ; Use "Flags: dontcopy" if you don't need uninstall time access
  19. Source: "MyDll.dll"; DestDir: "{app}"
  20.  
  21. [Code]
  22. const
  23.   MB_ICONINFORMATION = $40;
  24.  
  25. //importing a Windows API function
  26. function MessageBox(hWnd: Integer; lpText, lpCaption: String; uType: Cardinal): Integer;
  27. external 'MessageBoxA@user32.dll stdcall';
  28.  
  29. //importing a custom DLL function, first for Setup, then for uninstall
  30. procedure MyDllFuncSetup(hWnd: Integer; lpText, lpCaption: String; uType: Cardinal);
  31. external 'MyDllFunc@files:MyDll.dll stdcall setuponly';
  32.  
  33. procedure MyDllFuncUninstall(hWnd: Integer; lpText, lpCaption: String; uType: Cardinal);
  34. external 'MyDllFunc@{app}\MyDll.dll stdcall uninstallonly';
  35.  
  36. //importing a function for a DLL which might not exist at runtime
  37. procedure DelayLoadedFunc(hWnd: Integer; lpText, lpCaption: String; uType: Cardinal);
  38. external 'DllFunc@DllWhichMightNotExist.dll stdcall delayload';
  39.  
  40. function NextButtonClick(CurPage: Integer): Boolean;
  41. var
  42.   hWnd: Integer;
  43. begin
  44.   if CurPage = wpWelcome then begin
  45.     hWnd := StrToInt(ExpandConstant('{wizardhwnd}'));
  46.  
  47.     MessageBox(hWnd, 'Hello from Windows API function', 'MessageBoxA', MB_OK or MB_ICONINFORMATION);
  48.  
  49.     MyDllFuncSetup(hWnd, 'Hello from custom DLL function', 'MyDllFunc', MB_OK or MB_ICONINFORMATION);
  50.  
  51.     try
  52.       //if this DLL does not exist (it shouldn't), an exception will be raised
  53.       DelayLoadedFunc(hWnd, 'Hello from delay loaded function', 'DllFunc', MB_OK or MB_ICONINFORMATION);
  54.     except
  55.       //handle missing dll here
  56.     end;
  57.   end;
  58.   Result := True;
  59. end;
  60.  
  61. procedure CurUninstallStepChanged(CurUninstallStep: TUninstallStep);
  62. begin
  63.   // Call our function just before the actual uninstall process begins
  64.   if CurUninstallStep = usUninstall then
  65.   begin
  66.     MyDllFuncUninstall(0, 'Hello from custom DLL function', 'MyDllFunc', MB_OK or MB_ICONINFORMATION);
  67.     
  68.     // Now that we're finished with it, unload MyDll.dll from memory.
  69.     // We have to do this so that the uninstaller will be able to remove the DLL and the {app} directory.
  70.     UnloadDLL(ExpandConstant('{app}\MyDll.dll'));
  71.   end;
  72. end;
  73.